import requests
from eroica import headers_dict
from eroica import xpath
from eroica import url_add

headers = '''
accept
text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
accept-encoding
gzip, deflate, br, zstd
accept-language
zh-CN,zh;q=0.9,zh-TW;q=0.8
authorization
Basic YWRtaW46YWRtaW4=
cache-control
max-age=0
connection
keep-alive
host
ssr3.scrape.center
referer
https://scrape.center/
sec-ch-ua
"Google Chrome";v="137", "Chromium";v="137", "Not/A)Brand";v="24"
sec-ch-ua-mobile
?0
sec-ch-ua-platform
"Windows"
sec-fetch-dest
document
sec-fetch-mode
navigate
sec-fetch-site
same-site
sec-fetch-user
?1
upgrade-insecure-requests
1
user-agent
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
'''

url = 'https://ssr3.scrape.center/'

ses = requests.Session()
response = ses.get(url, headers=headers_dict(headers))
urlxpath = '//*[@id="index"]/div[1]//*/div/div[1]/a/@href'
urls = url_add(url, xpath(response, urlxpath))

for url in urls:
    html = ses.get(url, headers=headers_dict(headers))
    xpaths = {
        'title': '//*[@id="detail"]/div[1]/div/div/div[1]/div/div[2]/a/h2/text()',
        'author': '//*[@id="detail"]/div[1]/div/div/div[1]/div/div[3]/p[1]/text()',
        'content': '//*[@id="detail"]/div[2]/div/div/div/div/div/p/text()'
    }
    data = xpath(html, xpaths)
    print(data)
